import {
  Controller,
  Get,
  Post,
  Patch,
  Param,
  Delete,
  Query,
  Req,
  Body,
} from '@nestjs/common';
import { OrderService } from './order.service';
import { Public } from 'src/common/decorators/public.decorator';
import { ApiProperty, ApiQuery } from '@nestjs/swagger';

@Controller('order_web')
export class OrderController {
  constructor(private readonly orderService: OrderService) {}

  @Post()
  create() {
    return this.orderService.create();
  }

  @Post('/add_order')
  @ApiProperty({
    description: '用户添加一个订单',
  })
  async addOrder(@Req() request: any, @Body() body) {
    return await this.orderService.addOrder(
      +request.managerInfo.sub,
      +body.carId,
      +body.serviceId,
    );
  }

  @Get('get_order')
  @ApiProperty({ description: '分页获取用户的订单情况' })
  @ApiQuery({ name: 'pageSize', description: '数据条数', required: true })
  @ApiQuery({ name: 'currentPage', description: '当前页码', required: true })
  findOne(
    @Req() req,
    @Query('currentPage') currentPage,
    @Query('pageSize') pageSize,
    @Query('order_status') order_status,
    @Query('license_plate') license_plate,
  ) {
    return this.orderService.findAllOrderByUserId(
      +req.managerInfo.sub,
      +currentPage,
      +pageSize,
      order_status,
      license_plate,
    );
  }

  @Post('finish_order')
  finish(@Req() request: any, @Body() params) {
    const userId = request.managerInfo.sub;
    return this.orderService.finish(userId, params);
  }

  @Post('del_order/:id')
  deleted(@Param('id') id) {
    return this.orderService.deleted(id);
  }
}
